<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="author" content="order by dede58.com"/>
    <title>用户注册</title>
    <link rel="stylesheet" type="text/css" href="./css/login.css">

</head>
<body>

    <div class="regist">
        <div class="regist_center">
            <div class="regist_top">
                <div class="left fl">online注册</div>
                <div class="right fr"><a href="./index.html" target="_self">校园商城</a></div>
                <div class="clear"></div>
                <div class="xian center"></div>
            </div>
            <!--<div class="username">学&nbsp;&nbsp;&nbsp;&nbsp;号:&nbsp;<input id="schoolNumber" class="shurukuang" type="text" name="username"placeholder="请输入你的用户名"/></div>-->
            <!--&lt;!&ndash;<div class="username">学&nbsp;&nbsp;&nbsp;&nbsp;号:&nbsp;<input id="schoolNumber" class="shurukuang" type="text" name="username"placeholder="请输入你的学号"/></div>&ndash;&gt;-->
            <!--<div class="username">密&nbsp;&nbsp;&nbsp;&nbsp;码:&nbsp;<input id="schoolPassword" class="shurukuang" type="password" name="password" placeholder="请输入你的密码"/></div>-->

            <div class="regist_main center">
                <div class="username">用&nbsp;&nbsp;户&nbsp;&nbsp;名:&nbsp;&nbsp;<input id="userName" class="shurukuang"
                                                                                     type="text" name="username"
                                                                                     placeholder="请输入你的用户名"/><span>请不要输入汉字</span>
                </div>
                <div class="username">学&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:&nbsp;&nbsp;<input
                        id="schoolNumber" class="shurukuang" type="text" name="username" placeholder="请输入你的学号"/><span>请不要输入汉字</span>
                </div>
                <div class="username">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:&nbsp;&nbsp;<input
                        id="schoolPassword" class="shurukuang" type="password" name="password"
                        placeholder="请输入你的密码"/><span>请输入6位以上字符</span></div>

                <div class="username">确认密码:&nbsp;&nbsp;<input class="shurukuang" type="password" name="repassword"
                                                              placeholder="请确认你的密码"/><span>两次密码要输入一致哦</span></div>

            </div>
            <div class="regist_submit">
                <input class="submit" onclick="register()" type="submit" name="submit" value="立即注册">
            </div>

        </div>
    </div>
    <footer class="myfooter">
        <span >copyright @ 2018 online</span>
    </footer>
</body>
<script src="js/crabapple.js" type="text/javascript"></script>
<script>
    function register() {
        let userName = document.getElementById('userName').value
        let schoolNumber = document.getElementById('schoolNumber').value
        let schoolPassword = document.getElementById('schoolPassword').value

        let xmlhttpregister = new XMLHttpRequest();
        xmlhttpregister.onreadystatechange = function () {
            if (xmlhttpregister.readyState == 4 && xmlhttpregister.status == 200) {
                let re = JSON.parse(xmlhttpregister.responseText);
                console.log(re)
                if (re.success == true) {
                    setCookie('userId', re.user.userId, 1)
                    setCookie('userImg', re.user.userImg, 1)
                    setCookie('userName', re.user.userName, 1)
                    setCookie('qq', re.user.qq, 1)
                    setCookie('introduceMyself', re.user.introduceMyself, 1)
                    setCookie('prosecutions', re.user.prosecutions, 1)
                    setCookie('reputation', re.user.reputation, 1)
                    setCookie('schoolNumber', re.user.schoolNumber, 1)
                    setCookie('telephone', re.user.telephone, 1)
                    window.location.href = 'index.html';
                }
                else alert(re.errMsg)
            }
        }
            xmlhttpregister.open("GET", prime_url + 'user/registeruserpageinfo?' + 'userName=' + userName + '&schoolNumber=' + schoolNumber + '&schoolPassword=' + schoolPassword, true);
            xmlhttpregister.setRequestHeader('Content-Type', 'application/json')
            xmlhttpregister.send();
    }
</script>
</html>